package org.dxy.types.common;


public record CommandResult<T>(boolean success, T data, String msg) {

    private static final String DEFAULT_SUCCESS_MESSAGE = "Success";
    private static final String DEFAULT_FAIL_MESSAGE = "Fail";

    private static <T> CommandResult<T> of(boolean success, T data, String msg) {
        return new CommandResult<>(success, data, msg);
    }

    // 成功
    public static <T> CommandResult<T> success(T data) {
        return of(true, data, DEFAULT_SUCCESS_MESSAGE);
    }

    public static <T> CommandResult<T> success(T data, String msg) {
        return of(true, data, msg);
    }

    public static CommandResult<Void> success(String msg) {
        return of(true, null, msg);
    }


    // 失败
    public static CommandResult<Void> fail(String msg) {
        return of(false, null, msg);
    }

    public static <T> CommandResult<T> fail(T data, String msg) {
        return of(false, data, msg);
    }

    public static CommandResult<Void> fail() {
        return of(false, null, DEFAULT_FAIL_MESSAGE);
    }
}

